const router = require('koa-router')(),//可以用require直接调用，也可以实例化调用Router = require('koa-router')    router = new Router()
      tasks  = require('../models/tasks.js'),
      log = console.log;


router.prefix('/api/tasks');
router.get('/',async(ctx,next) => {
  
  let res = await tasks.getAllTasks(ctx.userId);

  ctx.body = res;
});

router.post('/',async(ctx,next) => {
  
  let { task } = ctx.request.body;

  log(`提交代办事项列表,task:${task}`);
  ctx.body = '添加成功';
});

router.put('/:id',async(ctx,next) => {
  
  let {id} = ctx.params;
  let {task} = ctx.request.body;

  log(`修改代办事项列表 id=${id},task:${task}`);
  ctx.body = '修改成功';
});

router.delete('/:id',async(ctx,next) => {
  
  let {id} = ctx.params;

  log(`删除代办事项列表,id=${id}`);
  ctx.body = '删除成功';
});

module.exports = router;
